import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../../../pojo/ImPojo.dart';
import '../../../util/FileUtil.dart';
import '../../../util/MessageUtil.dart';
import 'DocumentViewPage.dart';
import 'CodeViewPage.dart';
import 'PdfViewPage.dart';
import 'TextViewPage.dart';
import 'VideoViewPage.dart';

class FileViewPage extends StatelessWidget {

  final ImMessage message;

  const FileViewPage({ required this.message, super.key});

  @override
  Widget build(BuildContext context) {
    var messageExt = message.messageExt;
    if (messageExt == null) {
      message.initMessageExt();
      messageExt = message.messageExt;
    }
    var filePath = MessageUtil.getFilePath2(message);
    if (FileUtil.isPdf(message.content)) {
      return PdfViewPage(title: messageExt!.originalName, filePath: filePath);
    } else if (FileUtil.isVideo(message.content)) {
      return VideoViewPage(title: messageExt!.originalName, filePath: filePath);
    } else if (FileUtil.isDocument(message.content)) {
      return DocumentViewPage(title: messageExt!.originalName, filePath: filePath);
    } else if (FileUtil.isCode(message.content)) {
      return CodeViewPage(title: messageExt!.originalName, filePath: filePath);
    } else if (FileUtil.isCode(message.content)) {
      return CodeViewPage(title: messageExt!.originalName, filePath: filePath);
    } else {
      return TextViewPage(title: messageExt!.originalName, filePath: filePath);
    }
  }

}